# -*- coding: utf-8 -*-
"""
Created on Tue Feb 19 14:55:43 2013

@author: aponteeduarddo@gmail.com
Copyright Eduardo Aponte 2013.
"""

from mex_binder import binder_py

mx_eyelink_open = binder_py('mx_eyelink_open')
mx_eyelink_open.mx_c.headers = ['<eyelink.h>','"mex.h"']
mx_eyelink_open.mx_c.code = '''

INT16 _main( void )
{
    return eyelink_open(); 
}


void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    mwSize td[2] = {1,1};
    double *status;
    /* Verify input arguments. */
    if(nrhs > 1 ) {
        mexErrMsgTxt("Incorrect number of inputs");
    } else if(nlhs>1) {
        mexErrMsgTxt("Too many output arguments.");
    }
    
    plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
    status = mxGetPr(plhs[0]);    
    status[0] = (double ) _main();

    return;
    
}


'''

mx_eyelink_open.mx_c.mdoc = \
'''function [ status ] = mx_eyelink_open( )
%MX_EYELINK_OPEN Attempts to open a link connection to the EyeLink tracker.
% Simple connect to single Eyelink tracker. Equivalent to
% eyelink_open_node(broadcast_address, 0).
%
% Remarks: 
% The tracker address can be set by calling the function 
% set_eyelink_address(). If this address was "255.255.255.255" the call to 
% eyelink_open() will "broadcast" a request to any tracker, however this may
% fail if multiple Ethernet cards are installed. For the broadcast option to
% work use EyeLink I v2.1 or higher, EyeLink II v1.1 or higher. Before using
% this command, call either open_eyelink_connection(-1) or 
% open_eyelink_system () to prepare the link for use.
%
% Returns:
% 0 if successful.
% -200 if link could not be established.
% -201 if tracker did not respond.
% -203 if the versions of the EyeLink library and tracker are incompatible.
%
'''
mx_eyelink_open.write_c()
mx_eyelink_open.write_m()
mx_eyelink_open.compile()
mx_eyelink_open.write_sh()

